package com.lenovo.lcdm.type.controller;


import com.lenovo.lcdm.common.model.ResponseVo;
import com.lenovo.lcdm.type.dto.LocalAttributeDTO;
import com.lenovo.lcdm.type.service.TypeLocalAttributeService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * @author xujing
 * @desc local属性控制器
 * @date 2024/1/10
 */
@RestController
public class TypeLocalAttributeController {

    private final Logger logger = LoggerFactory.getLogger(TypeLocalAttributeController.class);

    @Autowired
    private TypeLocalAttributeService localAttributeService;


    @PostMapping("/local-attribute")
    public ResponseVo createLocalAttribute(@RequestBody LocalAttributeDTO localAttributeDTO) {
        ResponseVo response = new ResponseVo<>();
        localAttributeService.saveTypeLocalAttribute(localAttributeDTO);
        return response;
    }

    @PutMapping("/local-attribute")
    public ResponseVo<Object> updateLocalAttribute(@RequestBody LocalAttributeDTO localAttributeDTO) {
        ResponseVo<Object> response = new ResponseVo<>();
        localAttributeService.updateTypeLocalAttribute(localAttributeDTO);
        return response;
    }

    @DeleteMapping("/local-attribute/{id}")
    public ResponseVo deleteLocalAttribute(@PathVariable("id") Long id) {
        ResponseVo<Object> response = new ResponseVo<>();
        localAttributeService.deleteTypeLocalAttribute(id);
        return response;
    }

    @GetMapping("/local-attribute/{id}")
    public ResponseVo<LocalAttributeDTO> getLocalAttributeDetail(@PathVariable("id") Long id) {
        ResponseVo<LocalAttributeDTO> responseVo = new ResponseVo<>();
        LocalAttributeDTO data = localAttributeService.getLocalAttributeDetail(id);
        responseVo.setData(data);
        return responseVo;
    }

    @PutMapping("/local-attributes/internal-id")
    public ResponseVo<Object> updateInternalId(@RequestParam("ignore-existing") boolean ignoreExisting) {
        ResponseVo<Object> response = new ResponseVo<>();
        localAttributeService.updateInternalId(ignoreExisting);
        return response;
    }
}
